﻿using org.opensocial.client;
using System.Collections.Generic;
using org.opensocial.data;
using System;
using System.IO;

namespace OpenSocial.Sample.Web
{
    public class ActivityUpdate
    {
        public ActivityUpdate(string templateId, Dictionary<string, string> templateParameters)
        {
            this.TemplateId = templateId;
            this.TemplateParameters = templateParameters;
        }

        public string TemplateId;
        public Dictionary<string, string> TemplateParameters;
    }

    public class StatusMoodUpdate
    {
        public StatusMoodUpdate(string StatusMoodId, DateTime PostedDate)
        {
            this.StatusMoodId = StatusMoodId;
            this.PostedDate = PostedDate;
        }

        public string StatusMoodId;
        public DateTime PostedDate;
    }

    public class User
    {
        public User(
            string id,
            string albumId,
            string mediaItemId,
            string appId,
            StatusMoodUpdate statusMoodUpdate,
            ActivityUpdate activityUpdate)
        {
            this.Id = id;
            this.AlbumId = albumId;
            this.MediaItemId = mediaItemId;
            this.AppId = appId;
            this.StatusMoodUpdate = statusMoodUpdate;
            this.ActivityUpdate = activityUpdate;
        }

        public User(string id)
        {
            this.Id = id;
        }

        public string Id;
        public string AlbumId;
        public string MediaItemId;
        public string AppId;
        public StatusMoodUpdate StatusMoodUpdate;
        public ActivityUpdate ActivityUpdate;
    }

    public partial class Samples : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User user = new User(
                "[user ID here]", //required
                "[valid album ID for that user here]", //optional, used when fetching media items and albums
                "[valid media tiem ID for that user here]", //optional, used when fetching media items
                "[app ID here]", //optional, used when fetching activities by app ID

                //optional, used when fetching status/mood comments, at least an ID or a postedDate is required for this call, not both
                new StatusMoodUpdate("[status/mood update ID here]", new DateTime(/*[valid postedDate here]*/)),

                //optional, used when creating activities, template ID is required, but template parameters are optional when raising activities
                new ActivityUpdate("[template ID here]", new Dictionary<string, string>()
                {
                    {"[optional template parameter key here]", "[optional template parameter value here]"},
                    {"[optional template parameter key here]", "[optional template parameter value here]"}
                }));

            // put your social network identifier here, for example:
            //
            //OpenSocialClient client = new OpenSocialClient("orkut.com");
            //OpenSocialClient client = new OpenSocialClient("hi5.com");
            //OpenSocialClient client = new OpenSocialClient("myspace.com");
            OpenSocialClient client = new OpenSocialClient("[social network identifier here]"); 

            // set the base URL here for the social network, for example:
            //
            //client.setProperty(OpenSocialClient.Properties.REST_BASE_URI, "http://sandbox.orkut.com/social/rest");
            //client.setProperty(OpenSocialClient.Properties.REST_BASE_URI, "http://sandbox.hi5.com/social/rest");
            //client.setProperty(OpenSocialClient.Properties.REST_BASE_URI, "http://opensocial.myspace.com/roa/09");
            client.setProperty(OpenSocialClient.Properties.REST_BASE_URI, "[base URL here]");
            
            client.setProperty(OpenSocialClient.Properties.CONSUMER_SECRET, "[app's secret here]");
            client.setProperty(OpenSocialClient.Properties.CONSUMER_KEY, "[app's consumer key here]");
            client.setProperty(OpenSocialClient.Properties.VIEWER_ID, "[viewer ID here]");

            //for 3-legged scenarios, provide an access token and secret
            client.setProperty(OpenSocialClient.Properties.ACCESS_TOKEN, "[valid access token here]");
            client.setProperty(OpenSocialClient.Properties.ACCESS_TOKEN_SECRET, "[valid access token secret here]");

            //optional, set useLegacyFormat to false when accessing MySpace's 0.9 AppData APIs
            bool useLegacyFormat = false;

            try
            {
                // PERSON
                //FetchMe(client);
                //FetchMeWithFields(client);
                //FetchUserId(client, user.Id);
                //FetchUserIdWithFields(client, user.Id);

                // PEOPLE
                //FetchMeFriends(client);
                //FetchMeFriendsWithParameters(client);
                //FetchMeGroupWithParameters(client);
                //FetchUserIdFriends(client, user.Id);
                //FetchUserIdFriendsWithParameters(client, user.Id);
                //FetchUserIdGroupWithParameters(client, user.Id);

                // GROUPS
                //FetchMeGroups(client);
                //FetchUserIdGroups(client, user.Id);
                //FetchMeGroupsWithParameters(client);
                //FetchUserIdGroupsWithParameters(client, user.Id);

                // ACTIVITIES
                //FetchMeActivities(client);
                //FetchMeActivitiesWithParameters(client);
                //FetchMeAppActivities(client);
                //FetchMeAppActivitiesWithParameters(client);
                //FetchMeFriendActivities(client);
                //FetchUserIdFriendActivities(client, user.Id);
                //FetchUserIdGroupIdAppIdActivities(client, user.Id, "@self", "@app");
                //FetchUserIdGroupIdAppIdActivities(client, user.Id, "@friends", "@app");
                //FetchUserIdActivities(client, user.Id);
                //FetchUserIdAppActivities(client, user.Id);
                //CreateMeActivity(client, user.ActivityUpdate.TemplateId, user.ActivityUpdate.TemplateParameters);
                //CreateUserIdActivity(client, user.Id, user.ActivityUpdate.TemplateId, user.ActivityUpdate.TemplateParameters);

                // ALBUMS
                //FetchMeAlbums(client);
                //FetchUserIdAlbums(client, user.Id);
                //FetchUserIdAlbumsWithParameters(client, user.Id);
                //FetchMeAlbumsWithParameters(client);
                //FetchMeAlbumById(client, user.AlbumId);
                //FetchUserIdAlbumByIdWithParameters(client, user.Id, user.AlbumId);
                //CreateMeAlbum(client);
                //CreateUserIdAlbum(client, user.Id);

                // MEDIA ITEMS
                //FetchMeMediaItemsVideos(client);
                //FetchMeMediaItems(client, user.AlbumId);
                //FetchUserIdMediaItems(client, user.Id, user.AlbumId);
                //FetchMeMediaItemsWithParameters(client, user.AlbumId);
                //FetchUserIdMediaItemsWithParameters(client, user.Id, user.AlbumId);
                //FetchMeMediaItemById(client, user.AlbumId, user.MediaItemId);
                //FetchMeMediaItemByIdWithParameters(client, user.AlbumId, user.MediaItemId);
                //UploadImage(client, user.AlbumId);

                // MEDIA ITEM COMMENTS
                //FetchMeMediaItemComments(client, user.AlbumId, user.MediaItemId);
                //FetchUserIdMediaItemComments(client, user.Id, user.AlbumId, user.MediaItemId);
                //FetchMeMediaItemCommentsWithParameters(client, user.AlbumId, user.MediaItemId);
                //FetchUserIdMediaItemCommentsWithParameters(client, user.Id, user.AlbumId, user.MediaItemId);

                // STATUSMOOD
                //FetchMeStatusMood(client);
                //FetchUserIdStatusMood(client, user.Id);
                //FetchUserIdGroupIdStatusMood(client, user.Id);
                //FetchMeFriendsStatusMood(client);
                //FetchMeSupportedMoods(client);
                //FetchUserIdSupportedMoods(client, user.Id);
                //UpdateMeStatusMoodCustom(client);
                //UpdateMeStatusMoodBuiltIn(client);
                //UpdateUserIdStatusMoodCustom(client, user.Id);

                // STATUSMOOD COMMENTS
                //FetchMeStatusMoodComments(client, user.StatusMoodUpdate.StatusMoodId);
                //FetchUserIdStatusMoodComments(client, user.Id, user.StatusMoodUpdate.StatusMoodId);
                //FetchMeStatusMoodCommentsPostedDate(client, user.StatusMoodUpdate.PostedDate);
                //FetchMeStatusMoodCommentsWithParameters(client, user.StatusMoodUpdate.StatusMoodId);
                //FetchUserIdStatusMoodCommentsWithParameters(client, user.Id, user.StatusMoodUpdate.StatusMoodId);
                //FetchMeStatusMoodCommentsPostedDateWithParameters(client, user.StatusMoodUpdate.PostedDate);
                //CreateMeStatusMoodComments(client, user.StatusMoodUpdate.StatusMoodId);
                //CreateUserIdStatusMoodComments(client, user.Id, user.StatusMoodUpdate.StatusMoodId);
                //CreateUserIdStatusMoodCommentsPostedDate(client, user.Id, user.StatusMoodUpdate.PostedDate);

                // NOTIFICATIONS
                //CreateMeNotification(client, user.Id);
                //CreateUserIdNotification(client, user.Id, user.Id);

                // APP DATA
                //DeleteMeAppData(client);
                //UpdateMeAppDataKeyValue(client, useLegacyFormat);
                //UpdateMeAppDataDictionary(client, useLegacyFormat);
                //UpdateUserIdAppDataKeyValue(client, user.Id, useLegacyFormat);
                //UpdateUserIdAppDataDictionary(client, user.Id, useLegacyFormat);
                //FetchUserIdAppDataAll(client, user.Id);
                //FetchMeAppDataAll(client, user.Id);
                //FetchUserIdAppIdAppDataAll(client, user.Id, user.AppId);
                //FetchMeAppDataKeys(client, user.Id);
                //FetchMeFriendsAppDataKeys(client);
                //FetchMeFriendsAppDataAll(client);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

        #region Groups

        // fetches the groups for @me
        private void FetchUserIdGroupsWithParameters(OpenSocialClient client, string userId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first group to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of group to fetch
            parameters.Add("count", new OpenSocialRequestParameter("1"));

            // fetch the groups
            Response<Group> groups = client.fetchGroups(userId, parameters);

            // output the groups
            foreach (Group group in groups)
            {
                OutputGroup(group);
            }
        }

        // fetches the groups for @me
        private void FetchMeGroupsWithParameters(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first group to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of group to fetch
            parameters.Add("count", new OpenSocialRequestParameter("1"));

            // fetch the groups
            Response<Group> groups = client.fetchGroups(parameters);

            // output the groups
            foreach (Group group in groups)
            {
                OutputGroup(group);
            }
        }

        // fetches the groups for the specified user
        private void FetchUserIdGroups(OpenSocialClient client, string userId)
        {
            // fetch the groups
            Response<Group> groups = client.fetchGroups(userId);

            // output the groups
            foreach (Group group in groups)
            {
                OutputGroup(group);
            }
        }

        // fetches the groups for @me
        private void FetchMeGroups(OpenSocialClient client)
        {
            // fetch the groups
            Response<Group> groups = client.fetchGroups();

            // output the groups
            foreach (Group group in groups)
            {
                OutputGroup(group);
            }
        }

        #endregion

        #region AppData

        // deletes app data for @me and @app
        private void DeleteMeAppData(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // specify the app data keys to delete
            parameters.Add("fields", new OpenSocialRequestParameter("userId1,userId2"));

            client.deletePersonAppData(parameters);
        }

        // updates the app data for the specified key to the specified value, for @me and @app
        private void UpdateUserIdAppDataDictionary(OpenSocialClient client, string userId, bool useLegacyFormat)
        {
            // create some test objects
            Jayrock.Json.JsonObject obj1 = new Jayrock.Json.JsonObject();
            obj1["somekey"] = "some test value here";

            Jayrock.Json.JsonObject obj2 = new Jayrock.Json.JsonObject();
            obj2["somekey2"] = "some other test value";

            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("userId1", obj1.ToString());
            dictionary.Add("userId2", obj2.ToString());

            // update the app data
            client.updatePersonAppData(userId, dictionary, useLegacyFormat);
        }

        // updates the app data for the specified key to the specified value, for @me and @app
        private void UpdateUserIdAppDataKeyValue(OpenSocialClient client, string userId, bool useLegacyFormat)
        {
            // create a test object
            Jayrock.Json.JsonObject obj = new Jayrock.Json.JsonObject();
            obj["somekey"] = "some test value here";

            // update the app data
            client.updatePersonAppData(userId, "testkey_userId", obj.ToString(), useLegacyFormat);
        }

        // updates the app data for the specified key to the specified value, for @me and @app
        private void UpdateMeAppDataDictionary(OpenSocialClient client, bool useLegacyFormat)
        {
            // create some test objects
            Jayrock.Json.JsonObject obj1 = new Jayrock.Json.JsonObject();
            obj1["somekey"] = "some test value here";

            Jayrock.Json.JsonObject obj2 = new Jayrock.Json.JsonObject();
            obj2["somekey2"] = "some other test value";

            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("testkey1", obj1.ToString());
            dictionary.Add("testkey2", obj2.ToString());

            // update the app data
            client.updatePersonAppData("@me", dictionary, useLegacyFormat);
        }

        // updates the app data for the specified key to the specified value, for @me and @app
        private void UpdateMeAppDataKeyValue(OpenSocialClient client, bool useLegacyFormat)
        {
            // create a test object
            Jayrock.Json.JsonObject obj = new Jayrock.Json.JsonObject();
            obj["somekey"] = "some test value here";

            // update the app data
            client.updatePersonAppData("@me", "TEST", DateTime.Now.Ticks.ToString(), useLegacyFormat);
        }

        // fetches the app data for the @friends of @me for @app using the specified keys
        private void FetchMeFriendsAppDataAll(OpenSocialClient client)
        {
            // fetch the app data
            Response<AppData> appData = client.fetchFriendAppData("@me", "@app", "@friends");

            foreach (AppData ad in appData)
            {
                // output all of the keys for all of the users
                foreach (string id in ad.fieldNames())
                {
                    foreach (string key in ad.getFieldNamesForUser(id))
                    {
                        OutputAppData(ad, id, key);
                    }
                }
            }
        }

        // fetches the app data for the @friends of @me for @app using the specified keys
        private void FetchMeFriendsAppDataKeys(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // specify the app data keys to fetch
            parameters.Add("fields", new OpenSocialRequestParameter("style,style2"));

            // fetch the app data
            Response<AppData> appData = client.fetchFriendAppData("@me", "@app", "@friends", parameters);

            foreach (AppData ad in appData)
            {
                // output all of the keys for all of the users
                foreach (string id in ad.fieldNames())
                {
                    foreach (string key in ad.getFieldNamesForUser(id))
                    {
                        OutputAppData(ad, id, key);
                    }
                }
            }
        }

        // fetches @me's app data for @app using the specified keys
        private void FetchMeAppDataKeys(OpenSocialClient client, string userId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // specify the app data keys to fetch
            parameters.Add("fields", new OpenSocialRequestParameter("style,style2"));

            // fetch the app data
            AppData appData = client.fetchPersonAppData("@me", "@app", parameters);

            // output a couple knows key/values in the app data
            OutputAppData(appData, "myspace.com.person." + userId, "style");
            OutputAppData(appData, "myspace.com.person." + userId, "style2");
        }

        // fetches all the app data for the specified user and app
        private void FetchUserIdAppIdAppDataAll(OpenSocialClient client, string userId, string appId)
        {
            // fetch the app data
            AppData appData = client.fetchPersonAppData(userId, appId);

            // output a couple knows key/values in the app data
            OutputAppData(appData, "myspace.com.person." + userId, "style");
            OutputAppData(appData, "myspace.com.person." + userId, "style2");
        }

        // fetches all the app data for the specified user and @app
        private void FetchUserIdAppDataAll(OpenSocialClient client, string userId)
        {
            // fetch the app data
            AppData appData = client.fetchPersonAppData(userId);

            // output a couple knows key/values in the app data
            OutputAppData(appData, "myspace.com.person." + userId, "style");
            OutputAppData(appData, "myspace.com.person." + userId, "style2");
        }

        // fetches all the app data for @me and @app
        private void FetchMeAppDataAll(OpenSocialClient client, string userId)
        {
            // fetch the app data
            AppData appData = client.fetchPersonAppData();

            // output all of the keys for the user
            foreach (string id in appData.fieldNames())
            {
                foreach (string key in appData.getFieldNamesForUser(id))
                {
                    OutputAppData(appData, id, key);
                }
            }
        }

        #endregion

        #region Notifications

        // sends an app notification to the specified user on behalf of @me
        private void CreateUserIdNotification(OpenSocialClient client, string userId, string recipient)
        {
            Dictionary<string, string> buttonParams = new Dictionary<string, string>();
            buttonParams.Add("a", "b");

            Notification notification = new Notification();
            notification.RecipientIds = new List<string> { recipient };

            // media items are specified using API style URIs, e.g.:
            //"http://opensocial.myspace.com/roa/09/mediaItems/183399670/@self/542074/35556663"
            notification.MediaItems = new List<string> { "[URI of valid media item here]" };

            notification.TemplateParameters = new Dictionary<string, string>();
            notification.TemplateParameters.Add("content", "Hi ${recipient}, here's a notification from ${canvasUrl}");
            notification.TemplateParameters.Add("button0_label", "goto canvas");
            notification.TemplateParameters.Add("button0_surface", "canvas");
            notification.TemplateParameters.Add("button0_params", new Jayrock.Json.JsonObject(buttonParams).ToString());
            notification.TemplateParameters.Add("button1_label", "goto profile");
            notification.TemplateParameters.Add("button1_surface", "appProfile");

            Notification response = client.createNotification(userId, notification);

            OutputNotification(response);
        }

        // sends an app notification to the specified user on behalf of @me
        private void CreateMeNotification(OpenSocialClient client, string recipient)
        {
            Dictionary<string, string> buttonParams = new Dictionary<string, string>();
            buttonParams.Add("a", "b");

            Notification notification = new Notification();
            notification.RecipientIds = new List<string> { recipient };

            // media items are specified using API style URIs, e.g.:
            //"http://opensocial.myspace.com/roa/09/mediaItems/183399670/@self/542074/35556663"
            notification.MediaItems = new List<string> { "[URI of valid media item here]" };

            notification.TemplateParameters = new Dictionary<string, string>();
            notification.TemplateParameters.Add("content", "Hi ${recipient}, here's a notification from ${canvasUrl}");
            notification.TemplateParameters.Add("button0_label", "goto canvas");
            notification.TemplateParameters.Add("button0_surface", "canvas");
            notification.TemplateParameters.Add("button0_params", new Jayrock.Json.JsonObject(buttonParams).ToString());
            notification.TemplateParameters.Add("button1_label", "goto profile");
            notification.TemplateParameters.Add("button1_surface", "appProfile");

            Notification response = client.createNotification(notification);

            OutputNotification(response);
        }

        #endregion

        #region StatusMood

        // updates the status and mood for the specified user using a custom mood
        private void UpdateUserIdStatusMoodCustom(OpenSocialClient client, string userId)
        {
            StatusMood newStatusMood = new StatusMood();

            // new status goes here, use null for no status
            newStatusMood.Status = "some new status:" + DateTime.Now.ToString();

            // custom mood name goes here
            newStatusMood.MoodName = "some mood name";

            // mood picture goes here, if null/invalid then there's no picture, use @supportedMood to get this value
            newStatusMood.MoodPictureName = null;

            // update the status/mood
            client.updateStatusMood(userId, newStatusMood);
        }

        // updates the status and mood for @me using one of the pre-defined moods
        private void UpdateMeStatusMoodBuiltIn(OpenSocialClient client)
        {
            StatusMood newStatusMood = new StatusMood();

            // new status goes here, use null for no status
            newStatusMood.Status = "some new status:" + DateTime.Now.ToString();

            // get this value from @supportedMood
            newStatusMood.MoodId = 90;

            // update the status/mood
            client.updateStatusMood(newStatusMood);
        }

        // updates the status and mood for @me using a custom mood
        private void UpdateMeStatusMoodCustom(OpenSocialClient client)
        {
            StatusMood newStatusMood = new StatusMood();

            // new status goes here, use null for no status
            newStatusMood.Status = "some new status:" + DateTime.Now.ToString();

            // custom mood name goes here
            newStatusMood.MoodName = "some mood name";

            // mood picture goes here, if null/invalid then there's no picture, use @supportedMood to get this value
            newStatusMood.MoodPictureName = "artistic.gif";

            // update the status/mood
            client.updateStatusMood(newStatusMood);
        }

        // this will get the complete list of supported moods for @me
        private void FetchUserIdSupportedMoods(OpenSocialClient client, string userId)
        {
            // a groupId of "@supportedMood" will return the desired list
            Response<StatusMood> supportedMoods = client.fetchStatusMood(userId, "@supportedMood");

            // output the supported moods
            foreach (StatusMood mood in supportedMoods)
            {
                OutputStatusMood(mood);
            }
        }

        // this will get the complete list of supported moods for @me
        private void FetchMeSupportedMoods(OpenSocialClient client)
        {
            // a groupId of "@supportedMood" will return the desired list
            Response<StatusMood> supportedMoods = client.fetchStatusMood("@me", "@supportedMood");

            // output the supported moods
            foreach (StatusMood mood in supportedMoods)
            {
                OutputStatusMood(mood);
            }
        }

        // fetches the status and mood for the specified user and group
        private void FetchUserIdGroupIdStatusMood(OpenSocialClient client, string userId)
        {
            // fetch the status/mood
            Response<StatusMood> statusMoods = client.fetchStatusMood(userId, "@self");

            // output the status/moods
            foreach (StatusMood statusMood in statusMoods)
            {
                OutputStatusMood(statusMood);
            }
        }

        // fetches the status and mood for the specified user
        private void FetchUserIdStatusMood(OpenSocialClient client, string userId)
        {
            // fetch the status/mood
            Response<StatusMood> statusMoods = client.fetchStatusMood(userId);

            // output the media items
            foreach (StatusMood statusMood in statusMoods)
            {
                OutputStatusMood(statusMood);
            }
        }

        // fetches the status and mood for @me
        private void FetchMeStatusMood(OpenSocialClient client)
        {
            // fetch the status/mood
            Response<StatusMood> statusMoods = client.fetchStatusMood();

            // output the media items
            foreach (StatusMood statusMood in statusMoods)
            {
                OutputStatusMood(statusMood);
            }
        }

        // fetches the status and mood for the specified user and group
        private void FetchMeFriendsStatusMood(OpenSocialClient client)
        {
            // fetch the status/mood
            Response<StatusMood> statusMoods = client.fetchStatusMood("@me", "@friends");

            // output the status/moods
            foreach (StatusMood statusMood in statusMoods)
            {
                OutputStatusMood(statusMood);
            }
        }

        #endregion

        #region StatusMoodComments

        // this will fetch the statusmood comments for @me given a statusId
        private void FetchMeStatusMoodComments(OpenSocialClient client, string statusId)
        {
            // fetch the status/mood comments
            Response<StatusMoodComment> statusMoodComments = client.fetchStatusMoodComments(statusId);

            // output the media items
            foreach (StatusMoodComment statusMoodComment in statusMoodComments)
            {
                OutputStatusMoodComment(statusMoodComment);
            }
        }

        // this will fetch the statusmood comments for the given user and statusId
        private void FetchUserIdStatusMoodComments(OpenSocialClient client, string userId, string statusId)
        {
            // fetch the status/mood comments
            Response<StatusMoodComment> statusMoodComments = client.fetchStatusMoodComments(userId, statusId);

            // output the media items
            foreach (StatusMoodComment statusMoodComment in statusMoodComments)
            {
                OutputStatusMoodComment(statusMoodComment);
            }
        }

        // this will fetch the statusmood comments for @me given a postedDate
        private void FetchMeStatusMoodCommentsPostedDate(OpenSocialClient client, DateTime postedDate)
        {
            // fetch the status/mood comments by postedDate
            Response<StatusMoodComment> statusMoodComments = client.fetchStatusMoodComments(postedDate);

            // output the media items
            foreach (StatusMoodComment statusMoodComment in statusMoodComments)
            {
                OutputStatusMoodComment(statusMoodComment);
            }
        }

        // this will fetch the statusmood comments for @me given a statusId, with parameters
        private void FetchMeStatusMoodCommentsWithParameters(OpenSocialClient client, string statusId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the SMC to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of SMCs to fetch
            parameters.Add("count", new OpenSocialRequestParameter("2"));

            // include all the fields with the response
            parameters.Add("fields", new OpenSocialRequestParameter("@all"));

            // fetch the status/mood comments
            Response<StatusMoodComment> statusMoodComments = client.fetchStatusMoodComments(statusId, parameters);

            // output the media items
            foreach (StatusMoodComment statusMoodComment in statusMoodComments)
            {
                OutputStatusMoodComment(statusMoodComment);
            }
        }

        // this will fetch the statusmood comments for the given user and statusId, with parameters
        private void FetchUserIdStatusMoodCommentsWithParameters(OpenSocialClient client, string userId, string statusId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the SMC to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of SMCs to fetch
            parameters.Add("count", new OpenSocialRequestParameter("1"));

            // include all the fields with the response
            parameters.Add("fields", new OpenSocialRequestParameter("@all"));

            // fetch the status/mood comments
            Response<StatusMoodComment> statusMoodComments = client.fetchStatusMoodComments(userId, statusId, parameters);

            // output the media items
            foreach (StatusMoodComment statusMoodComment in statusMoodComments)
            {
                OutputStatusMoodComment(statusMoodComment);
            }
        }

        // this will fetch the statusmood comments for @me given a postedDate, with parameters
        private void FetchMeStatusMoodCommentsPostedDateWithParameters(OpenSocialClient client, DateTime postedDate)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the SMC to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of SMCs to fetch
            parameters.Add("count", new OpenSocialRequestParameter("2"));

            // include all the fields with the response
            parameters.Add("fields", new OpenSocialRequestParameter("@all"));

            // fetch the status/mood comments by postedDate
            Response<StatusMoodComment> statusMoodComments = client.fetchStatusMoodComments(postedDate, parameters);

            // output the media items
            foreach (StatusMoodComment statusMoodComment in statusMoodComments)
            {
                OutputStatusMoodComment(statusMoodComment);
            }
        }

        // adds a comment to a particular statusmood update for @me (comment on their own update)
        private void CreateMeStatusMoodComments(OpenSocialClient client, string statusId)
        {
            StatusMoodComment newStatusMoodComment = new StatusMoodComment();

            // the body of the comment goes here
            newStatusMoodComment.Body = "some new status comment:" + DateTime.Now.ToString();

            // add the statusmood comment
            client.createStatusMoodComment("@me", statusId, newStatusMoodComment);
        }

        // adds a comment to a particular statusmood update for the specified user
        private void CreateUserIdStatusMoodComments(OpenSocialClient client, string userId, string statusId)
        {
            StatusMoodComment newStatusMoodComment = new StatusMoodComment();

            // the body of the comment goes here
            newStatusMoodComment.Body = "some new status comment:" + DateTime.Now.ToString();

            // add the statusmood comment
            client.createStatusMoodComment(userId, statusId, newStatusMoodComment);
        }

        // adds a comment to a particular statusmood update for the specified user
        private void CreateUserIdStatusMoodCommentsPostedDate(OpenSocialClient client, string userId, DateTime postedDate)
        {
            StatusMoodComment newStatusMoodComment = new StatusMoodComment();

            // the body of the comment goes here
            newStatusMoodComment.Body = "some new status comment:" + DateTime.Now.ToString();

            // add the statusmood comment
            client.createStatusMoodComment(userId, postedDate, newStatusMoodComment);
        }

        #endregion

        #region MediaItems

        // uploads an image into the specified album
        private void UploadImage(OpenSocialClient client, string albumId)
        {
            string path = "C:\\path\\to\\image.jpg";

            MediaItem mediaItem = client.uploadMediaItem("@me", "@self", albumId,
                new MediaItem { Caption = "Photo Test " + System.DateTime.Now.Ticks.ToString() },
                File.ReadAllBytes(path), "image/jpg", "image");

            OutputMediaItem(mediaItem);
        }

        // fetches the specified media item in the specified album for @me
        private void FetchMeMediaItemByIdWithParameters(OpenSocialClient client, string albumId, string mediaItemId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // include the time of creation in the response
            parameters.Add("fields", new OpenSocialRequestParameter("created"));

            // fetch the media item
            Response<MediaItem> mediaItems = client.fetchMediaItems("@me", "@self", albumId, mediaItemId, parameters);

            // output the media items
            foreach (MediaItem mediaItem in mediaItems)
            {
                OutputMediaItem(mediaItem);
            }
        }

        // fetches the specified media item in the specified album for @me
        private void FetchMeMediaItemById(OpenSocialClient client, string albumId, string mediaItemId)
        {
            // fetch the media item
            Response<MediaItem> mediaItems = client.fetchMediaItems("@me", "@self", albumId, mediaItemId);

            // output the media items
            foreach (MediaItem mediaItem in mediaItems)
            {
                OutputMediaItem(mediaItem);
            }
        }

        // fetch the first media item in the specified album for @me
        private void FetchUserIdMediaItemsWithParameters(OpenSocialClient client, string userId, string albumId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first friend to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of friends to fetch
            parameters.Add("count", new OpenSocialRequestParameter("1"));

            // include the number of views with the response
            parameters.Add("fields", new OpenSocialRequestParameter("numViews"));

            // fetch the first media item in the album
            Response<MediaItem> mediaItems = client.fetchMediaItems(userId, "@self", albumId, null, parameters);

            // output the media item
            foreach (MediaItem mediaItem in mediaItems)
            {
                OutputMediaItem(mediaItem);
            }
        }

        // fetch the first media item in the specified album for @me
        private void FetchMeMediaItemsWithParameters(OpenSocialClient client, string albumId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first friend to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of friends to fetch
            parameters.Add("count", new OpenSocialRequestParameter("1"));

            // include the number of views with the response
            parameters.Add("fields", new OpenSocialRequestParameter("numViews"));

            // fetch the first media item in the album
            Response<MediaItem> mediaItems = client.fetchMediaItems("@me", "@self", albumId, null, parameters);

            // output the media item
            foreach (MediaItem mediaItem in mediaItems)
            {
                OutputMediaItem(mediaItem);
            }
        }

        // fetches the media items in the specified album for the specified user
        private void FetchUserIdMediaItems(OpenSocialClient client, string userId, string albumId)
        {
            // fetch the media items
            Response<MediaItem> mediaItems = client.fetchMediaItems(userId, "@self", albumId);

            // output the media items
            foreach (MediaItem mediaItem in mediaItems)
            {
                OutputMediaItem(mediaItem);
            }
        }

        // fetches the media items in the specified album for @me
        private void FetchMeMediaItemsVideos(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first friend to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of friends to fetch
            parameters.Add("count", new OpenSocialRequestParameter("100"));

            // fetch additional fields
            parameters.Add("fields", new OpenSocialRequestParameter("duration,description,numViews"));

            // fetch the media items
            Response<MediaItem> mediaItems = client.fetchMediaItems("@me", "@self", "@videos", null, parameters);

            // output the media items
            foreach (MediaItem mediaItem in mediaItems)
            {
                OutputMediaItem(mediaItem);
            }
        }

        // fetches the media items in the specified album for @me
        private void FetchMeMediaItems(OpenSocialClient client, string albumId)
        {
            // fetch the media items
            Response<MediaItem> mediaItems = client.fetchMediaItems("@me", "@self", albumId);

            // output the media items
            foreach (MediaItem mediaItem in mediaItems)
            {
                OutputMediaItem(mediaItem);
            }
        }

        #endregion

        #region MediaItemComments

        // fetches the media item comments for a particular media item, for @me
        private void FetchMeMediaItemComments(OpenSocialClient client, string albumId, string mediaItemId)
        {
            // fetch the media items
            Response<MediaItemComment> mediaItemComments = client.fetchMediaItemComments(albumId, mediaItemId);

            // output the media items
            foreach (MediaItemComment mediaItemComment in mediaItemComments)
            {
                OutputMediaItemComment(mediaItemComment);
            }
        }

        // fetches the media item comments for a particular media item, for a given user
        private void FetchUserIdMediaItemComments(OpenSocialClient client, string userId, string albumId, string mediaItemId)
        {
            // fetch the media items
            Response<MediaItemComment> mediaItemComments = client.fetchMediaItemComments(userId, albumId, mediaItemId);

            // output the media items
            foreach (MediaItemComment mediaItemComment in mediaItemComments)
            {
                OutputMediaItemComment(mediaItemComment);
            }
        }

        // fetches the media item comments for a particular media item, for @me, with paging parameters and additional author info
        private void FetchMeMediaItemCommentsWithParameters(OpenSocialClient client, string albumId, string mediaItemId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first MIC to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of MICs to fetch
            parameters.Add("count", new OpenSocialRequestParameter("2"));

            // get the author of the MIC
            parameters.Add("fields", new OpenSocialRequestParameter("author"));

            // fetch the media items
            Response<MediaItemComment> mediaItemComments = client.fetchMediaItemComments(albumId, mediaItemId, parameters);

            // output the media items
            foreach (MediaItemComment mediaItemComment in mediaItemComments)
            {
                OutputMediaItemComment(mediaItemComment);
            }
        }

        // fetches the media item comments for a particular media item, for a given user, with paging parameters and additional author info
        private void FetchUserIdMediaItemCommentsWithParameters(OpenSocialClient client, string userId, string albumId, string mediaItemId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first MIC to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of MICs to fetch
            parameters.Add("count", new OpenSocialRequestParameter("2"));

            // get the author of the MIC
            parameters.Add("fields", new OpenSocialRequestParameter("author"));

            // fetch the media items
            Response<MediaItemComment> mediaItemComments = client.fetchMediaItemComments(userId, albumId, mediaItemId, parameters);

            // output the media items
            foreach (MediaItemComment mediaItemComment in mediaItemComments)
            {
                OutputMediaItemComment(mediaItemComment);
            }
        }
        #endregion

        #region Albums

        // creates an album with a caption for the specified user
        private void CreateUserIdAlbum(OpenSocialClient client, string userId)
        {
            Album album = new Album();
            album.Caption = "caption," + DateTime.Now.ToString();

            Album response = client.createAlbum(userId, "@self", album);

            OutputAlbum(response);
        }

        // creates an album with a caption for @me
        private void CreateMeAlbum(OpenSocialClient client)
        {
            Album album = new Album();
            album.Caption = "caption," + DateTime.Now.ToString();

            Album response = client.createAlbum(album);

            OutputAlbum(response);
        }

        // fetches a particular album for the specified user
        private void FetchUserIdAlbumByIdWithParameters(OpenSocialClient client, string userId, string albumId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // add the number of media items in the album to the response
            parameters.Add("fields", new OpenSocialRequestParameter("mediaItemCount"));

            // fetch the default albums for the specified user
            Response<Album> album = client.fetchAlbums(userId, "@self", albumId, parameters);

            // output the album, there should be only one at most
            foreach (Album alb in album)
            {
                OutputAlbum(alb);
            }
        }

        // fetches a particular album for @me
        private void FetchMeAlbumById(OpenSocialClient client, string albumId)
        {
            // fetch the default albums for the specified user
            Response<Album> album = client.fetchAlbums("@me", "@self", albumId, null);

            // output the album, there should be only one at most
            foreach (Album alb in album)
            {
                OutputAlbum(alb);
            }
        }

        // fetches default albums for the specified user
        private void FetchMeAlbumsWithParameters(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first friend to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of friends to fetch
            parameters.Add("count", new OpenSocialRequestParameter("2"));

            // add the number of media items in the album to the response
            parameters.Add("fields", new OpenSocialRequestParameter("mediaItemCount"));

            // fetch the default albums for the specified user
            Response<Album> albums = client.fetchAlbums("@me", "@self", null, parameters);

            // loop through the list and output the results
            foreach (Album album in albums)
            {
                OutputAlbum(album);
            }
        }

        // fetches default albums for the specified user
        private void FetchUserIdAlbumsWithParameters(OpenSocialClient client, string userId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first friend to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of friends to fetch
            parameters.Add("count", new OpenSocialRequestParameter("2"));

            // add the number of media items in the album to the response
            parameters.Add("fields", new OpenSocialRequestParameter("mediaItemCount"));

            // fetch the default albums for the specified user
            Response<Album> albums = client.fetchAlbums(userId, "@self", null, parameters);

            // loop through the list and output the results
            foreach (Album album in albums)
            {
                OutputAlbum(album);
            }
        }

        // fetches default albums for the specified user
        private void FetchUserIdAlbums(OpenSocialClient client, string userId)
        {
            // fetch the default albums for the specified user
            Response<Album> albums = client.fetchAlbums(userId);

            // loop through the list and output the results
            foreach (Album album in albums)
            {
                OutputAlbum(album);
            }
        }

        // fetches default albums for @me
        private void FetchMeAlbums(OpenSocialClient client)
        {
            // fetch the default albums for @me
            Response<Album> albums = client.fetchAlbums();

            // loop through the list and output the results
            foreach (Album album in albums)
            {
                OutputAlbum(album);
            }
        }

        #endregion

        #region Activities

        // raises an app activity for @me
        private void CreateMeActivity(OpenSocialClient client, string templateId, Dictionary<string, string> templateParameters)
        {
            // create the activity object
            Activity activity = new Activity();
            activity.TitleId = templateId;
            activity.TemplateParameters = templateParameters;

            // raise the activity
            Activity response = client.createActivity(activity);

            // output the results (probably just the ID)
            OutputActivity(response);
        }

        // raises an app activity for @me
        private void CreateUserIdActivity(OpenSocialClient client, string userId, string templateId, Dictionary<string, string> templateParameters)
        {
            // create the activity object
            Activity activity = new Activity();
            activity.TitleId = templateId;
            activity.TemplateParameters = templateParameters;

            // raise the activity
            Activity response = client.createActivity(userId, activity);

            // output the results (probably just the ID)
            OutputActivity(response);
        }

        // fetches the activities for the friends of the specified user
        private void FetchUserIdFriendActivities(OpenSocialClient client, string userId)
        {
            // fetch the default activities for @me
            Response<Activity> activities = client.fetchActivitiesForFriends(userId);

            // loop through the list and output the results
            foreach (Activity activity in activities)
            {
                OutputActivity(activity);
            }
        }

        // fetches the activities for the friends of @me
        private void FetchMeFriendActivities(OpenSocialClient client)
        {
            // fetch the default activities for @me
            Response<Activity> activities = client.fetchActivitiesForFriends("@me");

            // loop through the list and output the results
            foreach (Activity activity in activities)
            {
                OutputActivity(activity);
            }
        }

        // fetches the app specific activities for @me and @app
        private void FetchUserIdAppActivities(OpenSocialClient client, string userId)
        {
            // fetch the default activities for @me and @app
            Response<Activity> activities = client.fetchActivitiesForApp(userId);

            // loop through the list and output the results
            foreach (Activity activity in activities)
            {
                OutputActivity(activity);
            }
        }

        // fetches the app specific activities for @me and @app
        private void FetchMeAppActivitiesWithParameters(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // "body" will return the body text and any media items
            parameters.Add("fields", new OpenSocialRequestParameter("body"));

            // fetch the default activities for @me and @app
            Response<Activity> activities = client.fetchActivities("@me", "@self", "@app", parameters);

            // loop through the list and output the results
            foreach (Activity activity in activities)
            {
                OutputActivity(activity);
            }
        }

        // fetches the app specific activities for @me and @app
        private void FetchMeAppActivities(OpenSocialClient client)
        {
            // fetch the default activities for @me and @app
            Response<Activity> activities = client.fetchActivitiesForApp();

            // loop through the list and output the results
            foreach (Activity activity in activities)
            {
                OutputActivity(activity);
            }
        }

        // fetches the activities for the specified user, group and app
        private void FetchUserIdGroupIdAppIdActivities(OpenSocialClient client, string userId, string groupId, string appId)
        {
            // fetch the default activities for @me
            Response<Activity> activities = client.fetchActivities(userId, groupId, appId);

            // loop through the list and output the results
            foreach (Activity activity in activities)
            {
                OutputActivity(activity);
            }
        }

        // fetches the activities for @me
        private void FetchUserIdActivities(OpenSocialClient client, string userId)
        {
            // fetch the default activities for @me
            Response<Activity> activities = client.fetchActivities(userId, "@self", string.Empty);

            // loop through the list and output the results
            foreach (Activity activity in activities)
            {
                OutputActivity(activity);
            }
        }

        private void FetchMeActivitiesWithParameters(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // "body" will return the body text and any media items
            parameters.Add("fields", new OpenSocialRequestParameter("mediaItems"));

            // fetch the default activities for @me and @app
            Response<Activity> activities = client.fetchActivities("@me", "@self", null, parameters);

            // loop through the list and output the results
            foreach (Activity activity in activities)
            {
                OutputActivity(activity);
            }
        }

        // fetches the activities for @me
        private void FetchMeActivities(OpenSocialClient client)
        {
            // fetch the default activities for @me
            Response<Activity> activities = client.fetchActivities();

            // loop through the list and output the results
            foreach (Activity activity in activities)
            {
                OutputActivity(activity);
            }
        }

        #endregion

        #region Friends

        // fetches the friends in the specified group for the viewer (@me), with paging support
        private void FetchUserIdGroupWithParameters(OpenSocialClient client, string userId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first friend to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of friends to fetch
            parameters.Add("count", new OpenSocialRequestParameter("100"));

            // the groupId on MySpace is a large negative number
            Response<Person> friends = client.fetchFriends(userId, "-9223232183946283786", parameters);

            // loop through the list and output the results
            foreach (Person person in friends)
            {
                OutputPerson(person);
            }
        }

        // fetches the friend list for the viewer (@me), with paging support
        private void FetchUserIdFriendsWithParameters(OpenSocialClient client, string userId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first friend to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of friends to fetch
            parameters.Add("count", new OpenSocialRequestParameter("100"));

            // request the friend list
            Response<Person> friends = client.fetchFriends(userId, parameters);

            // loop through the list and output the results
            foreach (Person person in friends)
            {
                OutputPerson(person);
            }
        }

        // fetches the default friend list for the viewer (@me)
        private void FetchUserIdFriends(OpenSocialClient client, string userId)
        {
            // request the friend list
            Response<Person> friends = client.fetchFriends(userId);

            // loop through the list and output the results
            foreach (Person person in friends)
            {
                OutputPerson(person);
            }
        }

        // fetches the friends in the specified group for the viewer (@me), with paging support
        private void FetchMeGroupWithParameters(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first friend to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of friends to fetch
            parameters.Add("count", new OpenSocialRequestParameter("100"));

            // the groupId on MySpace is a large negative number
            Response<Person> friends = client.fetchFriends("@me", "-9223232183946283786", parameters);

            // loop through the list and output the results
            foreach (Person person in friends)
            {
                OutputPerson(person);
            }
        }

        // fetches the friend list for the viewer (@me), with paging support
        private void FetchMeFriendsWithParameters(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // startIndex will be the index of the first friend to fetch
            parameters.Add("startIndex", new OpenSocialRequestParameter("1"));

            // count will be the total number of friends to fetch
            parameters.Add("count", new OpenSocialRequestParameter("100"));

            // request the friend list
            Response<Person> friends = client.fetchFriends(parameters);

            // loop through the list and output the results
            foreach (Person person in friends)
            {
                OutputPerson(person);
            }
        }

        // fetches the default friend list for the viewer (@me)
        private void FetchMeFriends(OpenSocialClient client)
        {
            // request the friend list
            Response<Person> friends = client.fetchFriends();

            // loop through the list and output the results
            foreach (Person person in friends)
            {
                OutputPerson(person);
            }
        }

        #endregion

        #region People

        // fetches the specified user with some additional fields
        private void FetchUserIdWithFields(OpenSocialClient client, string userId)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // add the fields you'd like to fetch for the user
            parameters.Add("fields", new OpenSocialRequestParameter("gender"));

            // request the person object
            Person person = client.fetchPerson(userId, parameters);

            // output the result to the screen
            OutputPerson(person);
        }

        // fetches the default parameters for the specified user
        private void FetchUserId(OpenSocialClient client, string userId)
        {
            // request the person object
            Person person = client.fetchPerson(userId);

            // output the result to the screen
            OutputPerson(person);
        }

        // fetches the viewer (@me) with some additional fields
        private void FetchMeWithFields(OpenSocialClient client)
        {
            // create the dictionary object
            Dictionary<string, OpenSocialRequestParameter> parameters = new Dictionary<string, OpenSocialRequestParameter>();

            // add the fields you'd like to fetch for the user
            parameters.Add("fields", new OpenSocialRequestParameter("gender,name,profileUrl"));

            // request the person object
            Person person = client.fetchPerson(parameters);

            // output the result to the screen
            OutputPerson(person);
        }

        // fetches the default parameters for the viewer (@me)
        private void FetchMe(OpenSocialClient client)
        {
            // request the person object
            Person person = client.fetchPerson();

            // output the result to the screen
            OutputPerson(person);
        }

        #endregion

        private void CheckNullAndOutput(string thing)
        {
            if (null != thing)
            {
                Response.Write(thing);
            }
        }

        private void CheckNullAndOutput(Person person, string field)
        {
            if (null != person.getField(field))
            {
                Response.Write(field + ": " + person.getField(field).StringValue + "<br>");
            }
        }

        private void OutputGroup(Group group)
        {
            Response.Write("----------<br>");

            Response.Write("Id: " + group.Id + "<br>");
            Response.Write("Title: " + group.Title + "<br>");
        }

        private void OutputStatusMood(StatusMood statusMood)
        {
            Response.Write("----------<br>");

            Response.Write("Id: " + statusMood.Id + "<br>");
            Response.Write("UserId: " + statusMood.UserId + "<br>");
            Response.Write("MoodId: " + statusMood.MoodId + "<br>");
            Response.Write("MoodName: " + statusMood.MoodName + "<br>");
            Response.Write("MoodPictureName: " + statusMood.MoodPictureName + "<br>");
            Response.Write("MoodPictureUrl: " + statusMood.MoodPictureUrl + "<br>");
            Response.Write("Status: " + statusMood.Status + "<br>");
            Response.Write("MoodStatusLastUpdated: " + statusMood.MoodStatusLastUpdated.ToString() + "<br>");
        }

        private void OutputStatusMoodComment(StatusMoodComment statusMoodComment)
        {
            Response.Write("----------<br>");

            Response.Write("AuthorId: " + statusMoodComment.AuthorId + "<br>");
            Response.Write("CommentId: " + statusMoodComment.CommentId + "<br>");
            Response.Write("Body: " + statusMoodComment.Body + "<br>");
            Response.Write("PostedDate: " + statusMoodComment.PostedDate.ToString() + "<br>");
        }

        private void OutputMediaItem(MediaItem mediaItem)
        {
            Response.Write("----------<br>");

            Response.Write("ID: " + mediaItem.Id + "<br>");
            Response.Write("AlbumId: " + mediaItem.AlbumId + "<br>");
            Response.Write("Created: " + mediaItem.Created.ToString() + "<br>");
            Response.Write("Description: " + mediaItem.Description + "<br>");
            Response.Write("Duration: " + mediaItem.Duration + "<br>");
            Response.Write("FileSize: " + mediaItem.FileSize + "<br>");
            Response.Write("Language: " + mediaItem.Language + "<br>");
            Response.Write("Location: " + mediaItem.Location + "<br>");
            Response.Write("MimeType: " + mediaItem.MimeType + "<br>");
            Response.Write("NumComments: " + mediaItem.NumComments + "<br>");
            Response.Write("NumViews: " + mediaItem.NumViews + "<br>");
            Response.Write("NumVotes: " + mediaItem.NumVotes + "<br>");
            Response.Write("Rating: " + mediaItem.Rating + "<br>");
            Response.Write("StartTime: " + mediaItem.StartTime + "<br>");

            //mediaItem.getField("msTaggedPeople").getValues()[0].getField("id").getStringValues()[0]
            if (null != mediaItem.getField("msTaggedPeople"))
            {
                Response.Write("MsTaggedPeople:<br>");
                Response.Write("-----<br>");

                foreach (OpenSocialObject oso in mediaItem.getField("msTaggedPeople").getValues())
                {
                    Response.Write("ID:" + oso.getField("id").StringValue + "<br>");
                    Response.Write("Name:" + oso.getField("displayName").StringValue + "<br>");
                    Response.Write("URL:" + oso.getField("profileUrl").StringValue + "<br>");
                    Response.Write("Image:" + oso.getField("thumbnailUrl").StringValue + "<br>");
                    Response.Write("-----<br>");
                }
            }

            if (null != mediaItem.TaggedPeople)
            {
                foreach (string taggedPeople in mediaItem.TaggedPeople)
                {
                    Response.Write("TaggedPeople: " + taggedPeople + "<br>");
                }
            }

            if (null != mediaItem.Tags)
            {
                foreach (string tags in mediaItem.Tags)
                {
                    Response.Write("Tags: " + tags + "<br>");
                }
            }

            Response.Write("<img src='" + mediaItem.ThumbnailUrl + "' /><br>");
            Response.Write("Title: " + mediaItem.Title + "<br>");
            Response.Write("Type: " + mediaItem.Type + "<br>");
            Response.Write("Url: " + mediaItem.Url + "<br>");
        }

        private void OutputMediaItemComment(MediaItemComment mediaItemComment)
        {
            Response.Write("----------<br>");
            Response.Write("Author:<br>");
            OutputPerson(mediaItemComment.Author);
            Response.Write("----------<br>");

            Response.Write("CommentId: " + mediaItemComment.CommentId + "<br>");
            Response.Write("Body: " + mediaItemComment.Body + "<br>");
            Response.Write("PostedDate: " + mediaItemComment.PostedDate.ToString() + "<br>");
        }

        private void OutputNotification(Notification notification)
        {
            Response.Write("----------<br>");

            Response.Write("TemplateId: " + notification.TemplateId + "<br>");

            if (null != notification.RecipientIds)
            {
                Response.Write("RecipientIds:");
                foreach (string recipient in notification.RecipientIds)
                {
                    Response.Write(recipient + ",");
                }
                Response.Write("<br>");
            }

            if (null != notification.TemplateParameters)
            {
                Response.Write("TemplateParameters:");
                foreach (string key in notification.TemplateParameters.Keys)
                {
                    Response.Write(key + ":" + notification.TemplateParameters[key] + "<br>");
                }
                Response.Write("<br>");
            }

            if (null != notification.MediaItems)
            {
                Response.Write("MediaItems:");
                foreach (string mediaItem in notification.MediaItems)
                {
                    Response.Write(mediaItem + ",");
                }
                Response.Write("<br>");
            }

            if (null != notification.getField("statusLink"))
            {
                Response.Write("Status Link: " + notification.getField("statusLink").StringValue + "<br>");
            }

            if (null != notification.getField("id"))
            {
                Response.Write("ID: " + notification.getField("id").StringValue + "<br>");
            }
        }

        private void OutputAlbum(Album album)
        {
            Response.Write("----------<br>");

            Response.Write("ID: " + album.Id + "<br>");
            Response.Write("Description: " + album.Description + "<br>");
            Response.Write("Location: " + album.Location + "<br>");
            Response.Write("MediaItemCount: " + album.MediaItemCount + "<br>");
            Response.Write("MediaMimeType: " + album.MediaMimeType + "<br>");
            Response.Write("MediaType: " + album.MediaType + "<br>");
            Response.Write("OwnerId: " + album.OwnerId + "<br>");
            Response.Write("<img src='" + album.ThumbnailUrl + "' /><br>");
            Response.Write("Title: " + album.Title + "<br>");
            Response.Write("Url: " + album.Url + "<br>");
        }

        private void OutputAppData(AppData appData, string userId, string key)
        {
            Response.Write(userId + " --> " + key + ":" + appData.getStringForUser(userId, key) + "<br>");
        }

        private void OutputActivity(Activity activity)
        {
            Response.Write("----------<br>");

            Response.Write("Title: " + activity.Title + "<br>");
            Response.Write("Body: " + activity.Body + "<br>");
            Response.Write("Id: " + activity.Id + "<br>");
            Response.Write("UserId: " + activity.UserId + "<br>");

            if (null != activity.getField("mediaItems"))
            {
                foreach (OpenSocialObject oso in activity.getField("mediaItems").getValues())
                {
                    MediaItem mi = new MediaItem();

                    foreach (string field in oso.fieldNames())
                    {
                        if (!oso.getField(field).IsComplex)
                        {
                            mi.setField(field, oso.getField(field));
                        }
                    }
                    OutputMediaItem(mi);
                }
            }

            if (null != activity.getField("postedTime"))
            {
                Response.Write("Posted Time: " + activity.getField("postedTime").StringValue + "<br>");
            }
        }

        private void OutputPerson(Person person)
        {
            Response.Write("----------<br>");

            // Output the name, ID, and gender of the requested person
            Response.Write("ID: " + person.Id + "<br>");
            Response.Write("Name: " + person.DisplayName + "<br>");
            Response.Write("Profile Url: " + person.ProfileUrl + "<br>");
            Response.Write("<img src='" + person.ThumbnailUrl + "' /><br>");
            Response.Write("Is Owner: " + person.IsOwner + "<br>");
            Response.Write("Is Viewer: " + person.IsViewer + "<br>");
            Response.Write("Has App: " + person.HasApp + "<br>");
            Response.Write("Updated: " + person.Updated.ToString() + "<br>");

            OutputAddress(person.CurrentLocation);

            CheckNullAndOutput(person, "gender");
            CheckNullAndOutput(person, "aboutMe");
        }

        private void OutputAddress(Address address)
        {
            if (null == address) return;

            Response.Write("Current Location:<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Country:" + address.Country + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;ExtendedAddress:" + address.ExtendedAddress + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Formatted:" + address.Formatted + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Latitude:" + address.Latitude + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Locality:" + address.Locality + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Longitude:" + address.Longitude + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;PoBox:" + address.PoBox + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;PostalCode:" + address.PostalCode + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Primary:" + address.Primary + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Region:" + address.Region + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;StreetAddress:" + address.StreetAddress + "<br>");
            Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Type:" + address.Type + "<br>");
        }
    }
}
